//
//  shipDetailViewController.m
//  WHB_logist
//
//  Created by 徐国庆 on 15/12/2.
//  Copyright (c) 2015年 turing. All rights reserved.
//

#import "shipDetailViewController.h"
#import "shipListCell.h"
#import "CWStarRateView.h"
#import "shipDetailCell.h"

@interface shipDetailViewController ()<UITableViewDataSource, UITableViewDelegate>

@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)OrderModel *order;

@end

@implementation shipDetailViewController

- (instancetype)initWithOrder:(OrderModel *)order{
    self = [super init];
    if (self) {
        self.order = order;
        NSLog(@"seld.order = %@", self.order);
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navtitle.text = @"货单详情";
    
    [self initWithView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *firstCell = @"shipDetailCell";
    shipDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:firstCell];
    if (cell == nil) {
        cell = [[shipDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:firstCell];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    cell.topLabel.backgroundColor = [UIColor HexStrWithColor:@"eeeeee"];
    cell.shipListNumberLabel.text = [NSString stringWithFormat:@"发货日期:%@", self.order.loadGoodsTime];//@"发货日期:2015-07-12";
    cell.shipListNumberLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.stateLabel.text = self.order.orderStatus;//@"取货中";
    cell.stateLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
//    cell.line1.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    
    cell.setoutAddressLabel.text = self.order.startAddressName;//@"深圳";
    cell.addressImageView.image = [UIImage imageNamed:@"icon_Cargo_to"];
    cell.aimAddressLabel.text = self.order.endAddressName;//@"上海";
    cell.mediumImageView.image = [UIImage imageNamed:@"icon_Cargo_cargo"];
    cell.mediumLabel.text = self.order.mediumName;//@"汽油";
    cell.weightImageView.image = [UIImage imageNamed:@"icon_Cargo_car"];
    cell.weightLabel.text = self.order.weight;//@"21吨";
    cell.receiveShipOverButton.backgroundColor = [UIColor HexStrWithColor:@"f8cc00"];
    //    [cell.receiveShipOverButton setImage:[UIImage imageNamed:@"icon_Button_received"] forState:UIControlStateNormal];
    //    [cell.receiveShipOverButton setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];
    [cell.receiveShipOverButton addTarget:self action:@selector(receiveShipOverButtonAction:) forControlEvents:UIControlEventTouchDown];
    cell.receiveShipOverButton.tag = 100 +indexPath.row;
    cell.line2.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    
    cell.remarkLabel.text = @"备注";
    cell.remarkLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.remarkContentLabel.text = self.order.note;//@"上午 早点来取货";
    cell.topLabel2.backgroundColor = [UIColor HexStrWithColor:@"eeeeee"];
    
    cell.receiveBusinessLabel.text = @"取货方";
    cell.receiveBusinessLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.receiveContentLabel.text = self.order.getOrgName;//@"中广核";
    cell.identificationImageView.image = [UIImage imageNamed:@"btn_icon_Confirmed_normal"];
    cell.callingButton.backgroundColor = [UIColor HexStrWithColor:@"f8cc00"];
    //    [cell.callingButton setImage:[UIImage imageNamed:@"icon_Mine_phone"] forState:UIControlStateNormal];
    //    [cell.callingButton setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];
    [cell.callingButton addTarget:self action:@selector(callingButtonAction:) forControlEvents:UIControlEventTouchDown];
    cell.callingButton.tag = 200 + indexPath.row;
    cell.line3.backgroundColor = [UIColor HexStrWithColor:@"999999"];
   
    
    cell.getBusinessLabel.text = @"收货方";
    cell.getBusinessLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.getContentLabel.text = self.order.receiptOrgName;//@"B集团";
    cell.identificationGetImageView.image = [UIImage imageNamed:@"btn_icon_Confirmed_normal"];
    cell.callingGetButton.backgroundColor = [UIColor HexStrWithColor:@"f8cc00"];
    //    [cell.callingButton setImage:[UIImage imageNamed:@"icon_Mine_phone"] forState:UIControlStateNormal];
    //    [cell.callingButton setImageEdgeInsets:UIEdgeInsetsMake(5, 10, 5, 65)];
    [cell.callingGetButton addTarget:self action:@selector(callingButtonAction:) forControlEvents:UIControlEventTouchDown];
    cell.callingGetButton.tag = 200 + indexPath.row;
    cell.topLabel3.backgroundColor = [UIColor HexStrWithColor:@"eeeeee"];

    
    cell.numberLabel.text = @"货单号";
    cell.numberLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.numberStateLabel.text = self.order.orderNo;//@"20150710001";
    cell.numberStateLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line4.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    
    cell.dateLabel.text = @"下单时间";
    cell.dateLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.dateStateLabel.text = self.order.orderTime;//@"2015-07-10";
    cell.dateStateLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line5.backgroundColor = [UIColor HexStrWithColor:@"999999"];

    cell.receiveTureLabel.text = @"取货确认";
    cell.receiveTureLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.receiveTureContentLabel.text = @"";
    cell.receiveTureContentLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line6.backgroundColor = [UIColor HexStrWithColor:@"999999"];

    cell.sendLabel.text = @"收货确认";
    cell.sendLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.sendContentLabel.text = self.order.takeTime;//@"";
    cell.sendContentLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line7.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    
    cell.qianshouLabel.text = @"签收确认";
    cell.qianshouLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.qianshouContentLabel.text = self.order.signTime;//@"";
    cell.qianshouContentLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line8.backgroundColor = [UIColor HexStrWithColor:@"999999"];

    CWStarRateView *ratingControl = [[CWStarRateView alloc]initWithFrame:CGRectMake(100, 5, 80, 20)];
//    [bottomView addSubview:ratingControl];
    ratingControl.scorePercent = [self.order.driverEvaluationStar floatValue];//0.6;
    ratingControl.hasAnimation = YES;
    
    cell.driverLabel.text = @"车主评星";
    cell.driverLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.driverContentLabel.text = @"";
    [cell.driverContentLabel addSubview:ratingControl];
    cell.driverContentLabel.userInteractionEnabled = YES;
    cell.driverContentLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line9.backgroundColor = [UIColor HexStrWithColor:@"999999"];

    
    CWStarRateView *ratingControl2 = [[CWStarRateView alloc]initWithFrame:CGRectMake(100, 5, 80, 20)];
    //    [bottomView addSubview:ratingControl];
    ratingControl2.scorePercent = [self.order.ownerEvaluationStar floatValue];
    ratingControl2.hasAnimation = YES;
    
    cell.shipMasterLabel.text = @"货主评星";
    cell.shipMasterLabel.textColor = [UIColor HexStrWithColor:@"999999"];
    cell.shipMasterContentLabel.text = @"";
    [cell.shipMasterContentLabel addSubview:ratingControl2];
    cell.shipMasterContentLabel.userInteractionEnabled = YES;
    cell.shipMasterContentLabel.textColor = [UIColor HexStrWithColor:@"ff6600"];
    cell.line10.backgroundColor = [UIColor HexStrWithColor:@"999999"];
    
    
    return cell;
    /*
    static NSString *firstCell = @"firstCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:firstCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:firstCell];
        
        if (indexPath.row == 0) {
            
            float firstHeight = 30;
            // "订单状态"
            UIView *stateView = [self titleAndContent:@"订单状态:" andContent:@"正在发货" withToAddress:nil];
            stateView.frame = CGRectMake(0, 0, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:stateView];
            
            // “车牌号”
            UIView *numberView = [self titleAndContent:@"车牌号:" andContent:@"2917362827" withToAddress:nil];
            numberView.frame = CGRectMake(0, stateView.frame.origin.y + stateView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:numberView];
            
            // "地址"
            UIView *addressView = [self titleAndContent:@"地址:" andContent:@"深圳" withToAddress:@"上海"];
            addressView.frame = CGRectMake(0, numberView.frame.origin.y + numberView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:addressView];
            
            // “发货日期”
            UIView *sendDateView = [self titleAndContent:@"发货日期:" andContent:@"2015-11-11" withToAddress:nil];
            sendDateView.frame = CGRectMake(0, addressView.frame.origin.y + addressView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:sendDateView];
            
            // “介质”
            UIView *mediumView = [self titleAndContent:@"介质:" andContent:@"汽油" withToAddress:nil];
            mediumView.frame = CGRectMake(0, sendDateView.frame.origin.y + sendDateView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:mediumView];
            
            // “重量”
            UIView *weightView = [self titleAndContent:@"重量:" andContent:@"21吨" withToAddress:nil];
            weightView.frame = CGRectMake(0, mediumView.frame.origin.y + mediumView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:weightView];
            
            // ”价格区间“
            UIView *priceView = [self titleAndContent:@"价格区间:" andContent:@"8000元" withToAddress:nil];
            priceView.frame = CGRectMake(0, weightView.frame.origin.y + weightView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:priceView];
            
            // ”备注“
            UIView *remarkView = [self titleAndContent:@"备注:" andContent:@"来之前打电话" withToAddress:nil];
            remarkView.frame = CGRectMake(0, priceView.frame.origin.y + priceView.frame.size.height, kUIScreenWidth, firstHeight);
            
        } else if (indexPath.row == 1){
            UIView *view = [self twoAndStreeView:@"取货方:" sendAndReceive:@"京东" isIdentification:YES starSevel:2.0 phone:@"15146001603"];
            view.frame = CGRectMake(0, 0, kUIScreenWidth, 80);
            [cell.contentView addSubview:view];
            return cell;
        } else if (indexPath.row == 2){
            UIView *view = [self twoAndStreeView:@"收货方:" sendAndReceive:@"天猫" isIdentification:YES starSevel:2.0 phone:@"15146001603"];
            view.frame = CGRectMake(0, 0, kUIScreenWidth, 80);
            [cell.contentView addSubview:view];
            
            return cell;
        } else if (indexPath.row == 3){
            float firstHeight = 30;
            // "货单号:"
            UIView *numberView = [self titleAndContent:@"货单号:" andContent:@"2917362827" withToAddress:nil];
            numberView.frame = CGRectMake(0, 0, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:numberView];
            
            // "下单时间:"
            UIView *orderTimeView = [self titleAndContent:@"下单时间:" andContent:@"2917362827" withToAddress:nil];
            orderTimeView.frame = CGRectMake(0, numberView.frame.origin.y + numberView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:orderTimeView];
            
            // "货单号:"
            UIView *receiveTureView = [self titleAndContent:@"取货确认:" andContent:@"已确认" withToAddress:nil];
            receiveTureView.frame = CGRectMake(0, orderTimeView.frame.origin.y + orderTimeView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:receiveTureView];
            
            // "货单号:"
            UIView *sendTureView = [self titleAndContent:@"送达确认:" andContent:@"已确认" withToAddress:nil];
            sendTureView.frame = CGRectMake(0, receiveTureView.frame.origin.y + receiveTureView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:sendTureView];
            
            // "货单号:"
            UIView *signTureView = [self titleAndContent:@"签收确认:" andContent:@"未确认" withToAddress:nil];
            signTureView.frame = CGRectMake(0, sendTureView.frame.origin.y + sendTureView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:signTureView];
            
            
            return cell;
        } else if (indexPath.row == 4){
            float firstHeight = 30;
            // 车主评星
            UIView *vehicleStarView = [self fiveCellView:@"车主评星:" withStar:2];
            vehicleStarView.frame = CGRectMake(0, 0, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:vehicleStarView];
            
            // 货主星评
            UIView *cargoView = [self fiveCellView:@"货主评星:" withStar:2];
            cargoView.frame = CGRectMake(0, vehicleStarView.frame.origin.y + vehicleStarView.frame.size.height, kUIScreenWidth, firstHeight);
            [cell.contentView addSubview:cargoView];
        }else{
            return cell;
        }
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
     */
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 600;
}

- (void)receiveShipOverButtonAction:(UIButton *)button{
    NSLog(@"取货完成");
}

/**
 *  拨打电话点击方法
 *
 *  @param button <#button description#>
 */
- (void)callingButtonAction:(UIButton *)button{
    NSString *phoneNum = @"15146001603";
    UIWebView *callphonewebview;
    if (callphonewebview==nil) {
        callphonewebview=[[UIWebView alloc]init];
    }
    [self.view addSubview:callphonewebview];
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNum]]];
    [callphonewebview loadRequest:request];

}


/**
 *  初始化视图
 */
- (void) initWithView{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight - kNavHeight) style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
